<?php
use oxide\plugin\PluginAbstract;
use oxide\http\Context;

class ShareThisPlugin extends PluginAbstract
{
   public function onInit(Context $context) 
   {
      $this->register('ContentDefaultViewStart');
      $this->register('ModuleContentInfoRenderContentFooter');
   }
   
   public function onContentDefaultViewStart($event, $sender, $args = null)
   {
      $publisher_key = $this->getConfig()->getValue('publisher_key', "ur-bed0b694-4eb0-cf4d-2b45-7a93622a60de");
      $snippet = '<script type="text/javascript">var switchTo5x=true;</script>';
      _html::script(null, $snippet);
      _html::script('http://w.sharethis.com/button/buttons.js');
      $snippet = '<script type="text/javascript">stLight.options({publisher: '.$publisher_key .', doNotHash: true, doNotCopy: true, hashAddressBar: false});</script>';
      _html::script(null, $snippet);
   }

   
   public function onModuleContentInfoRenderContentFooter($event, \oxide\application\View $sender = null, $arg = null)
   {
      if(!$sender->get('single_content')) return;
      $share_types = $this->getConfig()->getValue('share_types', 'facebook,twitter,email');
      $types = explode(',', $share_types);
      $types = array_map('trim', $types);
      $types = array_map('strtolower', $types);
              
      $items = $arg['terms'];
      if(in_array('facebook_like', $types)) 
         $items['Share this'][] = "<span class='st_fblike_hcount' displayText='Facebook Like'></span></dd>";
      if(in_array('facebook_share', $types))       
         $items['Share this'][] = "<span class='st_facebook_hcount' displayText='Facebook'></span>";
      if(in_array('twitter', $types))       
         $items['Share this'][] = "<span class='st_twitter_hcount' displayText='Tweet'></span>";
      if(in_array('email', $types))       
         $items['Share this'][] = "<span class='st_linkedin_hcount' displayText='LinkedIn'></span>";

   }

}
?>
